use std::collections::HashMap;

use axum::{
    extract::{Request, State},
    routing::{get, MethodFilter},
    Router,
};

async fn hello(
    mut state: State<HashMap<&'static str, &'static str>>,
    request: Request,
) -> &'static str {
    state.0.insert("bbb", "ccc");
    println!("{} {:?}", request.uri(), state);
    "呵呵和"
}

async fn hv(state: State<Vec<i32>>) -> &'static str {
    println!("{:?}", state);
    "11111"
}

#[tokio::main]
async fn main() {
    // axum::routing::on
    let mut map = HashMap::new();
    map.insert("MapKey", "MapValue");

    let v = vec![1, 2, 3, 4];
    // build our application with a single route
    let app = Router::new()
        .route("/", axum::routing::on(MethodFilter::GET, hello))
        .route("/hv", get(hv).with_state(v))
        .with_state(map);

    // run our app with hyper, listening globally on port 3000
    let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
    axum::serve(listener, app).await.unwrap();
    // axum::extract::Multipart
}
